//request请求
import {errdata} from 'api/errdata.js'
import { log } from 'util'
let Base64= require('./base64.js').Base64

const request = class {
	constructor(url, arg) {
		this.url = url
		this.arg = arg;
		// let query = {
		// 	token:uni.getStorageSync('token') ? uni.getStorageSync('token') : '',
		// 	userid : uni.getStorageSync('userid') ? uni.getStorageSync('userid')  :''
			
		// } 
		// if(query.token){
		// 	this.arg = {...arg,...query};
		// }else{
		// 	this.arg = arg;
		// }
		
		console.log(this.arg,'this.arg');
	}
     
	// post请求
	modepost() {
		return new Promise((resolve, reject) => {
			uni.showLoading({
				title:'加载中'
			})
			// let query = {
			// 	token:uni.getStorageSync('token') ? uni.getStorageSync('token') : '',
			// 	userid : uni.getStorageSync('userid') ? uni.getStorageSync('userid')  :''
			//  }
			
			uni.request({
					url: this.url,
					method: 'POST',
					data: this.arg,
					// header:query
				})
				.then(res => {
					  resolve(res[1].data);
					  uni.hideLoading();
				})
				.catch(err => {
					console.log(err,'err')
					reject(err)
					let errs = '服务器错误 请稍后再试'
					errdata.errlist(errs)
				})
		})
	}
	// get请求
	modeget() {
		return new Promise((resolve, reject) => {
			uni.showLoading({
				title:'加载中'
			})
			// let query = {
			// 	token:uni.getStorageSync('token') ? uni.getStorageSync('token') : '',
			// 	userid : uni.getStorageSync('userid') ? uni.getStorageSync('userid')  :''
			// }
			uni.request({
					url: this.url,
					method: 'GET',
					// header:query
				})
				.then(res => {
					resolve(res[1].data)
					uni.hideLoading()
				})
				.catch(err => {
					reject(err)
					let errs = '服务器错误 请稍后再试'
					errdata.errlist(errs)
				})
		})
	}
	
}

export default request
